﻿using System;
using CzfSDK;
using MySql.Data.MySqlClient;
using System.Collections;
using System.Collections.Generic;

namespace Server
{
	public static class MapManager
	{
		// 读取地图格子列表
		public static List<Hashtable> GetAllMapCell()
		{
			return GetAllCell ();
		}

		// 读取地图信息
		public static List<Hashtable> GetAllMap()
		{
			return GetAll ();
		}

		// 提交地图信息
		public static string CreateMap(string name, string info)
		{
			Add (name, info);
			return "ok";
		}

		#region DB
		// 获取地图格子列表
		public static List<Hashtable> GetAllCell()
		{
			var sql = "select * from mapcell";

			var dt = MysqlPool.current.ExecDataTable (sql);
			if (dt == null)
				return null;
			else
				return dt.ToList ();
		}

		// 获取地图列表
		public static List<Hashtable> GetAll()
		{
			var sql = "select * from map";

			var dt = MysqlPool.current.ExecDataTable (sql);
			if (dt == null)
				return null;
			else
				return dt.ToList ();
		}


		// 创建地图信息
		private static int Add(string name, string info)
		{
			var sql = "insert into map(name, info) values(@name, @info)";
			return MysqlPool.current.ExecuteNonQuery (sql, 
				new MySqlParameter ("@name", name),
				new MySqlParameter ("@info", info)
			);
		}
		#endregion
	}
}

